<!DOCTYPE html>
<#import "/common/common.html" as common>
<html>
<head>
	<@common.head title="微信wifi管理系统" keywords="" description=""/>
</head>
<body class="gray-bg">

    <div class="wrapper wrapper-content animated fadeInRight">
    	<div class="row">
            <div class="col-sm-12" id="userListDiv">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	 <!-- 操作按钮 -->
						<div class="rboor" id="toolbar">
							<button id="add" onclick="add()" class="btn btn-primary"><i class="fa fa-plus"></i> 新增</button>
							<!-- <button id="remove" onclick="remove()" class="btn btn-danger"><i class="fa fa-trash"></i> 删除</button> -->
							<button id="homepage" onclick="homepage()" class="btn btn-info"><i class="fa fa-home"></i> 设置主页</button>
							<button id="synchrony" onclick="synchrony()" class="btn btn-success"><i class="fa fa-refresh"></i> 同步微信平台数据</button>
					    </div>
                         <table id="table"
                         	   data-toolbar="#toolbar"
				               data-url="${basePath}/wxstore/pageList"
				               data-id-field="id"
				               data-click-to-select="true"
				               data-side-pagination="server"
				               data-pagination="true"
				               data-icon-size="outline"
				               data-show-refresh="true"
				               data-show-columns="true"
				               data-show-export="true" 
				               data-show-toggle="true"
				               data-page-size="20"
				               data-page-list="[20, 100, ALL]"
				               data-pagination-first-text="首页"
							   data-pagination-pre-text="上一页"
							   data-pagination-next-text="下一页"
							   data-pagination-last-text="末页"
				               >
				        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Page-Level Scripts -->
    <@common.remoteModal id="homepageModal"/>
    
    <script>
	$(function () {
		list();
	});
	
	function list(){
		$('#table').bootstrapTable({
	        columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                }, {
                    title: 'ID',
                    field: 'id',
                    align: 'left',
                    visible: false,
                    switchable: false,
                    valign: 'middle'
                }, {
                    title: '门店名称',
                    field: 'business_name',
                    align: 'left',
                    valign: 'middle'
                }, {
                    title: '门店地址',
                    field: 'address',
                    align: 'left',
                    valign: 'middle',
                    formatter: function(value, row, index){
	                	return row.province + row.city + row.district + value;
	                }
                }, {
                    title: '顶部常驻入口',
                    field: 'bar_type',
                    align: 'left',
                    valign: 'middle',
                    formatter: function(value, row, index){
	                	if(value == 0) {
	                		return "欢迎光临" + row.wxuser_name + "!";
	                	}else if(value == 1) {
	                		return "欢迎光临" + row.business_name + "!";
	                	}else if(value == 2) {
	                		return "已连接" + row.wxuser_name + "Wi-Fi!";
	                	}else if(value == 3) {
	                		return "已连接" + row.business_name + "Wi-Fi!";
	                	}else {
	                		return value;
	                	}
	                }
                }, {
                    title: '主页地址',
                    field: 'homepage',
                    align: 'left',
                    valign: 'middle',
                    formatter: function(value, row, index){
                    	if(value != null) {
	                		return "<a href='" + value + "' target='_blank'>" + value + "</a>";
                    	}else {
                    		return value;
                    	}
	                }
                }, {
                    title: '所属公众号',
                    field: 'wxuser_name',
                    align: 'left',
                    valign: 'middle'
                }, {
                    title: '类目',
                    field: 'categories',
                    align: 'left',
                    valign: 'middle'
                }
	        ],
	        queryParams: function(params) {
	            $('#searchbar').find('select[name], input[name]').each(function () {
	                params[$(this).attr('name')] = $(this).val();
	            });
	        	return params;
	        },
	        queryParamsType: "" // When requesting remote data, you can send additional parameters by modifying queryParams. If queryParamsType = 'limit', the params object contains: 
					// limit, offset, search, sort, order Else, it contains: 
	        		// pageSize, pageNumber, searchText, sortName, sortOrder. 
	        		// Return false to stop request.
    	}).on('check.bs.table uncheck.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
	    	//$("#edit").prop('disabled', $("#table").bootstrapTable('getSelections').length != 1);
            //$("#remove").prop('disabled', !$("#table").bootstrapTable('getSelections').length);
            //selections = getIdSelections();
        });

	    $(window).resize(function () {
	        $('#table').bootstrapTable('resetView');
	    });
	}
	
	// 新增门店
	function add(){
		window.open("${basePath}/wxstore/goAdd", "_self");
	}
	
	// 设置门店主页
	function homepage(){
		var $selections = $("#table").bootstrapTable("getSelections");
		if($selections.length == 0) {
			toastr.warning("您没有选择任何项,请您选中后操作.","");
			return;
		}
   		var ids = [];
   		for(var index in $selections) {
   			ids.push($selections[index].id);
   		}
   		$("#homepageModal").modal({
    	    remote: "${basePath}/wxstore/goHomepage?ids=" + ids.join(",")
    	})
   		
	}
	
	// 同步平台数据
	function synchrony(){
		swal({
      		title: "同步平台数据时间可能会很长",
      		text: "确定执行吗?",
      		type: "warning",
      		showCancelButton: true,
      		confirmButtonColor: '#DD6B55',
      		confirmButtonText: '确定',
      		cancelButtonText: "取消",
      		closeOnConfirm: false
      	},
      	function(){
      		var loading = layer.load();
      		// 同步门店
      		$.post("${basePath}/wxstore/synchrony",function(){
      			layer.close(loading);
      			swal({
               		title: "操作成功",
               		type: "success",
               		showCancelButton: false,
               		confirmButtonColor: '#18a689',
               		confirmButtonText: '确定',
               		closeOnConfirm: true
                 },
               	function(){
               		$("#table").bootstrapTable('refresh');
               	});
      		},"json")
      		
      	});
	}
	
    </script>
</body>

</html>